package j06tongbu;

class Run1 implements Runnable{
    public void run() {
        while (J3jiekou.count>0){
            //1   2      1
            synchronized (Run1.class){
                if(J3jiekou.count<=0){
                    return;
                }
                System.out.println(Thread.currentThread().getName()+"卖票="+J3jiekou.count);
                J3jiekou.count--;
            }
        }
    }
}

public class J3jiekou {
    static int count = 100;

    public static void main(String[] args) {
        Run1 run1 = new Run1();

        Thread t1 = new Thread(run1);
        Thread t2 = new Thread(run1);
        t1.setName("t1");
        t2.setName("t22222");

        t1.start();
        t2.start();
    }
}
